<?php
class collection_collect_params {
	
	protected $_params = array();
	public function __construct($params) {
		try {
			$this->_params = @unserialize($params);
		} catch (Exception $e) {
			$this->_params = array();
		}
	}
	
	public function __toString() {
		return serialize($this->_params);
	}
	
	public function toArray() {
		return (array) $this->_params;
	}
		
	public function __call($method, array $args) {
		if(preg_match('/^get(\w+?)$/', $method, $matches)) {
			//默认：true
			$def = isset($args[0]) ? $args[0] : null;
			$name = preg_replace('/([A-Z]+)/s', '_$1', $matches[1]);
			return $this->get(trim($name, '_'), $def);
		}
		return null;
	}
	
	public function get($name, $def = null) {
		$name = strtolower($name);
		if(isset($this->_params[$name])) {
			return $this->_params[$name];
		}
		return $def;
	}
	
}
